﻿using System;
using System.Web.UI;

namespace UDS.SubModule.Query
{
    /// <summary>
    /// Google 的摘要说明。
    /// </summary>
    public partial class GooglePage : Page
    {
        protected override void OnInit(EventArgs e)
        {
            cmdSearch.Click += cmdSearch_Click;
            lbPerference.Click += lbPerference_Click;
            chkDocument.CheckedChanged += chkDocument_CheckedChanged;
            base.OnInit(e);
        }

        private void Page_Load(object sender, EventArgs e)
        {
        }

        private void lbPerference_Click(object sender, EventArgs e)
        {
            panPreference.Visible = !panPreference.Visible;
            if (!panPreference.Visible)
                lbPerference.Text = "偏好设置<<";
            else
                lbPerference.Text = "偏好设置>>";
        }

        private void cmdSearch_Click(object sender, EventArgs e)
        {
            int Range = 0;
            int SearchType = 0;

            if (chkTitle.Checked)
                Range = Range + 1;
            if (chkContent.Checked)
                Range = Range + 2;
            if (chkAuthor.Checked)
                Range = Range + 4;
            if (chkAttach.Checked)
                Range = Range + 8;
            if (chkDocument.Checked)
                SearchType += 1;
            if (chkMail.Checked)
                SearchType += 2;
            //			if(chkBBS.Checked ==true)
            //				SearchType +=4;
            if (Range == 0)
            {
                Response.Write("<script language='javascript'>alert('请输选择查询范围！');</script>");
                return;
            }
            if (SearchType == 0)
            {
                Response.Write("<script language='javascript'>alert('请输选择查询类型！');</script>");
                return;
            }
            string KeyString;

            if (txtKey.Text == "")
                KeyString = "%"; //Response.Write("<script language='javascript'>alert('请输入关键字！');</script>");
            else
                KeyString = txtKey.Text;
            if ((Range & 0x08) == 0x08)
            {
                if (KeyString.Length <= 1)
                {
                    if ((KeyString.ToUpper().CompareTo(" ") >= 0 && KeyString.ToUpper().CompareTo("~") <= 0) || (KeyString.CompareTo("0") >= 0 && KeyString.CompareTo("9") <= 0))
                        Response.Write("<script language='javascript'>alert('检索附件时不能查询少于一个字符！');</script>");
                    else
                        Response.Redirect("Listview.aspx?Key=" + KeyString + "&Range=" + Range + "&SearchType=" + SearchType);
                }
                else
                    Response.Redirect("Listview.aspx?Key=" + KeyString + "&Range=" + Range + "&SearchType=" + SearchType);
            }
            else
                Response.Redirect("Listview.aspx?Key=" + KeyString + "&Range=" + Range + "&SearchType=" + SearchType);
        }

        private void chkDocument_CheckedChanged(object sender, EventArgs e)
        {
        }

        #region Web Form Designer generated code

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        #endregion
    }
}